Get premium membership and access questions with answers, video lessons as well as revision papers.

Given the following class, show how to initialize a ten-element array so that x has the values 1 through 10. class samp { i x; public: samp(int n) {x...

      

Given the following class, show how to initialize a ten-element array so that x has the values 1 through 10.
class samp {
i x;
public:
samp(int n) {x = n; }
int getx() {return x ;}
};

  

Answers


Davis
#include
using namespace std;
class samp {
int x;
public:
samp(inx=n;}
int getx() {return x;}
};
samp A[10] ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int i;
for(i=0; i<10; i++) cout << A[i].getx() << ' ';
n";
return 0;
Githiari answered the question on May 29, 2018 at 18:45


Next: Show how to allocate a float and an int by using new. Also, show how to free them by using delete.
Previous: Using c++ language, create a function called recip() that takes one double reference parameter.Have the function change the value of that parameter into its reciprocal.Write...

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions